Class SlideBar extends Box
public var index=0;
public var dotColor=["#4fff","#cfff"];
var body;
var dotBox;
var tween;
var startTime;
function SlideBar(){
	this.startTime=G.now;
	this.setSize("f",270);
	this.body=this.addChild(Box);
	this.body.setW("f");
	this.dotBox=this.addChild(Box);
	this.changeSelf();
}
function resetSelf(){
	for(var i=this.children.length-1;i>=0;i--){
		var box=this.children[i];
		if(box==this.body||box==this.dotBox) continue;
		box.setSize("f",this.h);
		this.body.addChild(box,0);
	}
	var count=this.body.children.length;
	if(count==0) return;
	var index=this.index;
	var x=this.body.x;
	if(x<=-G.w){
		index++;
		x+=G.w;
		if(Drag.target==this.body) Drag.fromPos.x+=G.w;
		if(index>=count) index=0;
	}
	else if(x>=G.w){
		index--;
		x-=G.w;
		if(Drag.target==this.body) Drag.fromPos.x-=G.w;
		if(index<=-1) index=count-1;
	}
	this.index=index;
	this.body.setX(x);
	var index2=x<=0?index+1:index-1;
	if(index2<=-1) index2=count-1;
	if(index2>=count) index2=0;
	for(var i=0;i<count;i++){
		var cell=this.body.children[i];
		cell.setVisible(i==index||i==index2);
	}
	var cell=this.body.children[index];
	cell.setX(0);
	var cell2=this.body.children[index2];
	var dir=(index2==index+1)?1:-1;
	if(index==count-1&&index2==0) dir=1;
	if(count==2&&this.body.x>0){
		dir=-1;
	}
	if(cell!=cell2) cell2.setX(dir*G.w);

	var x=0;
	for(var i=0;i<count;i++){
		var dot=this.dotBox.children[i];
		if(!dot){
			dot=this.dotBox.addChild(new Box({w:16,h:16,bg:["#fff",,8]}));
		}
		var c=this.dotColor[this.index==i?1:0];
		dot.setBg([c,,8]);
		dot.setX(x);
		x+=dot.w+10;
	}
	var w=x-10;
	this.dotBox.setX((G.w-w)/2);
	this.dotBox.setY(this.h-40);
}
function play(dir){
	if(this.body.children.length<=1) return;
	this.startTime=G.now;
	var count=this.body.children.length;
	var index=this.index+dir;
	if(index<=-1) index=count-1;
	if(index>=count) index=0;
	this.body.transit({x:-dir*G.w,ease:1},[this,this.play2,index]);
}
function play2(index){
	this.index=index;
	this.body.setX(0);
	this.changeSelf();
}
function onDrag(finish){
	if(!finish){
		this.changeSelf();
		return;
	}
	var dir=0;
	var x=this.body.x;
	if(x<0){
		if(-x>60) dir=1;
	}
	else{
		if(x>60) dir=-1;
	}
	this.play(dir);
}
function onPress(){
	if(this.body.children.length<=1) return;
	G.isPress=false;
	var x=this.body.x;
	this.body.transit(null);
	this.body.startDrag([x-2*G.w,0,x+4*G.w,0],[this,this.onDrag],false);
}
function onClick(){
	this.dispatchEvent(G.newEvent(Evt.CHANGE));
	if(this.parent==G.stage){
		this.remove();
	}
}